#!/sbin/openrc-run
name="Nomad"
description="An easy-to-use, flexible, and performant workload orchestrator"
description_healthcheck="Check health status"
description_reload="Reload configuration"

extra_started_commands="healthcheck reload"

command="/usr/sbin/${RC_SVCNAME}"
command_args="${nomad_opts}"
command_user="root:root"

supervisor=supervise-daemon
output_log="/var/log/${RC_SVCNAME}.log"
error_log="/var/log/${RC_SVCNAME}.log"
respawn_max=0
respawn_delay=10
healthcheck_timer=60

depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -f -m 0644 -o "$command_user" "$output_log" "$error_log"
}

healthcheck() {
	$command agent-info > /dev/null 2>&1
}

reload() {
	start_pre \
		&& ebegin "Reloading $RC_SVCNAME configuration" \
		&& $supervisor "$RC_SVCNAME" --signal HUP
	eend $?
}
